using System;
using System.Collections.Generic;
using System.Text;
using AAM.DAL;
using CMS.BIZ;
using AAM.BIZ;
using AAM.SQL;

namespace CMS.BOP
{
    public class SqlBizDownloadProvider : SqlBizObjectProvider<BizDownload>
    {

        public BizDownload Read(int downloadID)
        {
            return Read(new ObjectID(BizDownload.ObjectType,new object[]{downloadID}));
        }
        public bool Delete(int downloadID)
        {
            return Delete(new ObjectID(BizDownload.ObjectType, new object[] { downloadID }));
        }
        public BizDownload Find(int downloadID)
        {
            return Find(new ObjectID(BizDownload.ObjectType, new object[] { downloadID }));
        }


        public List<BizDownload> ReadByFolder(int? parentFolderID)
        {
            Command command;
            string order = " ORDER BY FileName";
            if (parentFolderID == null)
            {
                command = Connection.CreateCommand("SELECT * FROM " + Table.TableName + " WHERE ParentFolderID IS NULL" + order);
            }
            else
            {
                command = Connection.CreateCommand("SELECT * FROM " + Table.TableName + " WHERE ParentFolderID=?" + order);
                command.AddParameter(parentFolderID);
            }
            return CreateListFromCommand(command);
        }
    }
}
